package com.itheima.app.controller;

import com.itheima.app.manager.MakeFriendManager;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.domain.vo.RecommendUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class MakeFriendController {

    @Autowired
    private MakeFriendManager makeFriendManager;

    // 今日佳人
    @GetMapping("/tanhua/todayBest")
    public ResponseEntity findTodayBest() {
        // 调用manager
        return makeFriendManager.findTodayBest();
    }

    // 推荐用户列表
    @GetMapping("/tanhua/recommendation")
    public ResponseEntity findRecommendUser(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "8") Integer pageSize) {
        // 调用manager
        return makeFriendManager.findRecommendUser(pageNum, pageSize);
    }

    // 推荐用户详情
    @GetMapping("/tanhua/{recommendUserId}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable Long recommendUserId) {
        // 调用manager
        return makeFriendManager.personalInfo(recommendUserId);
    }

    // 查看陌生人问题（聊一下）
    @GetMapping("/tanhua/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestParam("userId") Long recommendUserId) {
        // 调用manager
        return makeFriendManager.strangerQuestions(recommendUserId);
    }

    // 最近访客
    @GetMapping("/movements/visitors")
    public ResponseEntity visitors() {
        // 调用manager
        return makeFriendManager.visitors();
    }

    // 上报地理位置
    @PostMapping("/baidu/location")
    public ResponseEntity saveUserLocation(@RequestBody Map<String, Object> map) {
        // 1.接收请求参数
        double latitude = (double) map.get("latitude");
        double longitude = (double) map.get("longitude");
        String addrStr = map.get("addrStr").toString();

        System.out.println("上报自己的位置：" + map);
        // 2.调用 manager
        return makeFriendManager.saveUserLocation(latitude, longitude, addrStr);
    }

    // 搜附近
    @GetMapping("/tanhua/search")
    public ResponseEntity searchNearUserVo(String gender, Integer distance) {
        // 调用 manager
        return makeFriendManager.searchNearUserVo(gender, distance);
    }

    // 探花卡片
    @GetMapping("/tanhua/cards")
    public ResponseEntity tanhuaCards() {
        // 调用manager
        ResponseEntity responseEntity = makeFriendManager.findRecommendUser(1, 20);
        // 从响应体取出pageBeanVo，再取出list集合
        PageBeanVo pageBeanVo = (PageBeanVo) responseEntity.getBody();
        List<RecommendUserVo> list = (List<RecommendUserVo>) pageBeanVo.getItems();
        // 返回list集合
        return ResponseEntity.ok(list);
    }
}
